﻿#region BSD 3-Clause License
/* Copyright (c) 2012, Intel Corporation
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *    
 * 3. Neither the name of Intel Corporation nor the names of its contributors may
 *    be used to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#endregion

using System.Collections.Generic;
using System.Collections.ObjectModel;
using SpartanUnit;
using OpenHopla.Geometry;

namespace OpenHopla.UnitTests.Root.Geometry
{
    /// <summary>
    /// a collection of test cases
    /// </summary>
    partial class TriangleTesterShould : TestSuite
    {
        #region Test Data

        private TriangleTester _triangleTester;
        private Triangle _ChristiansTriangle;
        private Triangle _345Triangle1;
        private Triangle _345Triangle2;
        private Triangle _42RightTriangle;
        private ICollection<Triangle> _345Triangles;

        #endregion

        #region TriangleTester.IsScalene Test Cases

        /// <summary>
        /// This test case was created by John Spurgeon and his Little Brother,
        /// Christian, on February 22, 2012. It tests whether TriangleTester
        /// can correctly classify a triangle that Christian created as scalene.
        /// </summary>
        /// <remarks>
        /// We know that TriangleTester should classify the triangle that Christian
        /// created as scalene, because we drew the triangle on graph paper and verified
        /// that the lengths of the three sides of the triangle were all different. The
        /// lengths of the sides were about 12.5 inches, 14 inches, and 16 and 1/8th
        /// inches as measured using two 12-inch rulers.
        /// </remarks>
        [TestCase]
        public void ClassifyChristiansTriangleAsScalene()
        {
            Assert.IsTrue(_triangleTester.IsScalene(_ChristiansTriangle));
        }

        [TestCase]
        public void Classify345TrianglesAsScalene()
        {
            int triangleNumber = 0;
            foreach (Triangle triangle in _345Triangles)
            {
                triangleNumber++;
                string comment = "Triangle No. " + triangleNumber;
                Assert.IsTrue(_triangleTester.IsScalene(triangle), comment);
            }
        }

        #endregion

        #region TrangleTester.IsRight Test Cases

        [TestCase]
        public void Classify345TrianglesAsRight()
        {
            int triangleNumber = 0;
            foreach (Triangle triangle in _345Triangles)
            {
                triangleNumber++;
                string comment = "Triangle No. " + triangleNumber;
                Assert.IsTrue(_triangleTester.IsRight(triangle), comment);
            }
        }

        [TestCase]
        public void Classify42RightTriangleAsRight()
        {
            Assert.IsTrue(_triangleTester.IsRight(_42RightTriangle));
        }

        #endregion

        #region TriangleTester.IsIsosceles Test Cases

        [TestCase]
        public void Classify42RightTriangleAsIsosceles()
        {
            Assert.IsTrue(_triangleTester.IsIsosceles(_42RightTriangle));
        }

        #endregion

    }

    /// <summary>
    /// test fixture
    /// </summary>
    partial class TriangleTesterShould : TestSuite
    {
        public override void Setup()
        {
            base.Setup();
            SetupTriangles();
            _triangleTester = new TriangleTester();
        }

        public override void Teardown()
        {
            base.Teardown();
            TeardownTriangles();
            _triangleTester = null;
        }

        private void SetupTriangles()
        {
            Setup345Triangles();
            SetupChristiansTriangle();
            Setup42RightTriangle();
        }

        private void TeardownTriangles()
        {
            Teardown345Triangles();
            TeardownChristiansTriangle();
            Teardown42RightTriangle();
        }

        private void Setup42RightTriangle()
        {
            List<OrderedPair> vertices = new List<OrderedPair>();
            vertices.Add(new OrderedPair(-2, 0));
            vertices.Add(new OrderedPair(0, 2));
            vertices.Add(new OrderedPair(2, 0));
            _42RightTriangle = new Triangle(vertices);
        }

        private void Teardown42RightTriangle()
        {
            _42RightTriangle = null;
        }

        private void SetupChristiansTriangle()
        {
            List<OrderedPair> vertices = new List<OrderedPair>();
            vertices.Add(new OrderedPair(5, 5));
            vertices.Add(new OrderedPair(7, -7));
            vertices.Add(new OrderedPair(-7, -6));
            _ChristiansTriangle = new Triangle(vertices);
        }

        private void TeardownChristiansTriangle()
        {
            _ChristiansTriangle = null;
        }

        private void Setup345Triangle1()
        {
            List<OrderedPair> vertices = new List<OrderedPair>();
            vertices.Add(new OrderedPair(0, 0));
            vertices.Add(new OrderedPair(3, 0));
            vertices.Add(new OrderedPair(3, 4));
            _345Triangle1 = new Triangle(vertices);
        }

        private void Setup345Triangle2()
        {
            List<OrderedPair> vertices = new List<OrderedPair>();
            vertices.Add(new OrderedPair(1.5, 0));
            vertices.Add(new OrderedPair(-2.5, 0));
            vertices.Add(new OrderedPair(-2.5, 3));
            _345Triangle2 = new Triangle(vertices);
        }

        private void Setup345Triangles()
        {
            Setup345Triangle1();
            Setup345Triangle2();
            _345Triangles = new Collection<Triangle>();
            _345Triangles.Add(_345Triangle1);
            _345Triangles.Add(_345Triangle2);
        }

        private void Teardown345Triangles()
        {
            _345Triangles = null;
            _345Triangle1 = null;
            _345Triangle2 = null;
        }
    }
}
